package com.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 目标对象,
 * Created by CrazyShaQiuShi on 2017/1/22.
 */
public class Subject {
    //存储所有的观察者
    private List<Observer> readers = new ArrayList<>();

    //注册观察者
    public void registObserver(Observer reader) {
        readers.add(reader);
    }

    //取消订阅
    public void detachObserver(Observer reader) {
        readers.remove(reader);
    }

    public void notifyObservers() {
        for (Observer reader : readers) {
            System.out.print(this);
            reader.update(this);
        }
    }
}
